<template>
  <el-container class="home-container">
    <!-- <el-aside :width="isCollapse ? '64px' : '200px'"> -->
    <el-menu
      router
      ref="menu"
      :class="['home-menu', isCollapse ? 'collapse-menu' : '']"
      :collapse="isCollapse"
      :collapse-transition="false"
    >
      <div class="logo">
        <i class="el-icon-s-help"></i>
        <h1 v-if="!isCollapse">Manager</h1>
      </div>

      <el-menu-item index="/dashboard">
        <!--引入字节的图标要在前面加icon -->
        <!-- <icon-home theme="outline" size="20" fill="#333" /> -->
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </el-menu-item>

      <el-menu-item index="/category">
        <i class="el-icon-menu"></i>
        <span slot="title">分类管理</span>
      </el-menu-item>

      <el-menu-item index="/post">
        <i class="el-icon-document"></i>
        <span slot="title">文章导航</span>
      </el-menu-item>

      <el-menu-item index="/manage">
        <i class="el-icon-ice-cream-round"></i>
        <span slot="title">用户管理</span>
      </el-menu-item>
    </el-menu>
    <!-- </el-aside> -->
    <el-container>
      <el-header>
        <i
          class="el-icon-caret-right"
          @click="handleCollapse"
          :class="isCollapse ? 'isCollapse' : ''"
        ></i>
        <el-button type="danger" size="small" @click="handleOutLogin"
          >退出登录</el-button
        >
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      isCollapse: false,
      category: [],
    }
  },
  mounted() {
    // console.log(this.$refs['menu'])
    // console.log(this.$route)
    this.$refs['menu'].activeIndex = this.$route.path
  },
  methods: {
    handleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    handleOutLogin() {
      if (confirm('您是否确定退出登录?')) {
        localStorage.setItem('isLogin', 0)
        this.$router.push('/login')
      }
    },
  },
}
</script>

<style>
.home-container {
  height: 100vh;
}
.el-aside {
  background-color: rgb(255, 255, 255);
  transition: all 0.4;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgb(255, 253, 203);
  font-size: 20px;
  color: aqua;
}
.el-header i {
  transition: all 0.5;
  cursor: pointer;
}
.el-main {
  background-color: rgb(255, 252, 157);
}
.logo {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  height: 60px;
  background-color: rgb(116, 215, 255);
  color: rgb(255, 255, 255);
  font-size: 28px;
}
.el-icon-s-help {
  margin: -10px;
}
.isCollapse {
  transform: rotate(-180deg);
}
.home-menu {
  width: 200px;
  transition: all 1s;
}
.collapse-menu {
  width: 64px;
  margin-bottom: 10px;
}
</style>
